/**
 * Created by root on 17-4-9.
 */
var http = require('http');
var querystring = require('querystring');
var postData = querystring.stringify({
    'content': 'nodejs学习',
    'mid': 8837
});

var options = {
    hostname: 'www.imooc.com',
    port: 80,
    path: '/course/docomment',
    method: 'POST',
    headers: {
         'Accept':'application/json, text/javascript, */*; q=0.01',
         'Accept-Encoding':'gzip, deflate',
         'Accept-Language':'zh-CN,zh;q=0.8',
         'Connection':'keep-alive',
         'Content-Length':postData.length,
         'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8',
         'Cookie':'imooc_uuid=cf30dae9-8f37-48fc-959d-966ce207506a; imooc_isnew_ct=1490764153; loginstate=1; apsid=I5OWM5NTdjZjM4NTA1NTIzNWY4MTc1OGRlNDFkMmQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMzEyNjQxNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAxMDcyNjg1NjA1QHFxLmNvbQAAAAAAAAAAAAAAAAAAADViNTkxMTJiODUwZWM4MjM2ODkyNzM2YzVjZmI1MDA3pkHbWKZB21g%3DNG; last_login_username=1072685605%40qq.com; IMCDNS=0; PHPSESSID=kl60r2tj3c93b689mdtvvgtor6; Hm_lvt_f0cfcccd7b1393990c78efdeebff3968=1491122063,1491543612,1491702550,1491729331; Hm_lpvt_f0cfcccd7b1393990c78efdeebff3968=1491729331; imooc_isnew=2; cvde=58e9fbb140b94-8',
         'Host':'www.imooc.com',
         'Origin':'http://www.imooc.com',
         'Referer':'http://www.imooc.com/video/8837',
         'User-Agent':'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36',
         'X-Requested-With':'XMLHttpRequest'
    }
};

var req = http.request(options, function (res) {
    console.log('Status: ' + res.statusCode);
    console.log('headers: ' + JSON.stringify(res.headers));
    res.on('data', function (chunk) {
        console.log(Buffer.isBuffer(chunk));
        console.log(typeof chunk);
    });

    res.on('end', function () {
        console.log('评论完毕')
    });
});

req.on('error', function (e) {
    console.log("Error: " + e.message);
});
req.write(postData);
req.end();